package com.sixks.app.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author colin
 * @date: 02/03/2014
 * @time: 22:03
 */
public class AttrName {
    private String id;

    private Map names;
    private String values;

    private String namesZh;
    private String namesEn;

    private List<AttrValue> attrValues = new ArrayList<AttrValue>();

    private String required;

    public String getRequired() {
        return required;
    }

    public void setRequired(String required) {
        this.required = required;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
        for(AttrValue each : attrValues){
            each.setBelongTo(Integer.valueOf(this.id));
        }
    }

    public Map getNames() {
        return names;
    }

    public void setNames(Map names) {
        this.names = names;
        this.namesZh = names.get("zh").toString();
        this.namesEn = names.get("en").toString();
    }

    public String getValues() {
        return values;
    }

    public void setValues(String values) {
        this.values = values;
        JSONArray array = JSON.parseArray(values);
        for (Object anArray : array) {
            JSONObject jobj = (JSONObject) anArray;
            AttrValue cate = JSON.toJavaObject(jobj, AttrValue.class);
            if(this.id != null){
                cate.setBelongTo(Integer.valueOf(this.getId()));
            }
            attrValues.add(cate);
        }
    }

    public List<AttrValue> getAttrValues() {
        return attrValues;
    }

    public String getNamesZh() {
        return namesZh;
    }

    public String getNamesEn() {
        return namesEn;
    }

    public void setNamesZh(String namesZh) {
        this.namesZh = namesZh;
    }

    public void setNamesEn(String namesEn) {
        this.namesEn = namesEn;
    }
}
